package com.by.service.impl;

import com.by.bean.ForwardUser;
import com.by.bean.PageBean;
import com.by.bean.User;
import com.by.bean.UserType;
import com.by.crud.BaseServiceImpl;
import com.by.mapper.ForwardUserMapper;
import com.by.mapper.UserMapper;
import com.by.query.ForwardUserQuery;
import com.by.service.ForwardUserService;
import com.by.utils.Assert;
import com.github.pagehelper.PageHelper;

import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

/**
 * date 2025/2/17 20:03
 * author bjj
 * decoration
 * version 1.0
 * since jdk11
 */
@Service
@SuppressWarnings("all")
public class ForwardUserServiceImpl extends BaseServiceImpl<ForwardUser, ForwardUserMapper> implements ForwardUserService {
    @Autowired
    UserMapper userMapper;

    @Override
    public PageBean query(ForwardUserQuery query) {
        PageHelper.startPage( query.getPage(),query.getPageSize());
        List list = baseMapper.query(query);
        PageInfo pageInfo = new PageInfo(list);
        return new PageBean(query.getPage(),query.getPageSize(),pageInfo.getTotal(),list);
    }

    @Transactional
    @Override
    public int save(ForwardUser forwardUser) {
        User user = new User(forwardUser.getAccount(), forwardUser.getPassword(), UserType.FORWARDER_USER);
        int rs = userMapper.save(user);
        Assert.isZero(rs,"新增失败");
        forwardUser.setId(user.getId());
        return super.save(forwardUser);
    }

}
